home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / MYIO.ZIP / MYSTREAM.H < prev   
C/C++ Source or Header  |  1995-11-02  |  2KB  |  93 lines

  1. // Mystream.h
  2. // iostream interface for class Myio
  3. // Defines the following classes:
  4. //  Mystreambuf     derived from streambuf - buffer management & I/O interface
  5. //  Mystreambase    base class used for initialisation & object reference
  6. //  Myiostream      customised iostream, derived from iostream/Mystreambase
  7. //
  8. // Written by David L Nugent, June 1993
  9. //
  10.  
  11. # if !defined(_Mystream_h)
  12. # define _Mystream_h 1
  13. # include <iostream.h>
  14. # include "Myio.h"
  15.  
  16.     //
  17.     // Mystreambuf
  18.     // This is the class which does all the actual I/O
  19.     // handling and (optional) buffer management
  20.     //
  21.  
  22. class Mystreambuf : public streambuf
  23. {
  24.  
  25.   public:
  26.  
  27.     Mystreambuf (Myio * mPtr);
  28.  
  29.   protected:
  30.  
  31.     virtual int overflow (int = EOF);
  32.     virtual int underflow ();
  33.     virtual int sync ();
  34.  
  35.   private:
  36.  
  37.     Myio * mptr;    // Points to the Myio instance to
  38.                     // which this stream is attached
  39.     char _back[2];  // Holder for putback
  40.  
  41. };
  42.  
  43.  
  44. class Mystreambase : public virtual ios
  45. {
  46.  
  47.   public:
  48.  
  49.     Mystreambase (Myio * mPtr);
  50.     Mystreambuf * rdbuf (void);
  51.  
  52.   protected:
  53.  
  54.     Mystreambuf mystreambuf;
  55.  
  56. };
  57.  
  58. inline
  59. Mystreambase::Mystreambase (Myio * mPtr)
  60.     : mystreambuf (mPtr)
  61. {}
  62.  
  63. inline Mystreambuf *
  64. Mystreambase::rdbuf (void)
  65.     {   return &mystreambuf;    }
  66.  
  67.  
  68. class Mystream : public Mystreambase, public iostream
  69. {
  70.  
  71.   public:
  72.  
  73.     Mystream (Myio * mPtr);
  74.     ~Mystream (void);
  75. };
  76.  
  77.     //
  78.     // class Mystream constructor
  79.     // This uses Mystreambase to set up the Mystreambuf
  80.     // which can then be used to initialise iostream.
  81.     //
  82.  
  83. inline
  84. Mystream::Mystream (Myio * m)
  85.     : Mystreambase (m), iostream (rdbuf())
  86. {}
  87.  
  88. inline
  89. Mystream::~Mystream (void)
  90.     {}
  91.  
  92. # endif     // _Mystream_h
  93.